package com.genntii.examManager.controller;

import com.genntii.examManager.common.constant.CommonConstant;
import com.genntii.examManager.common.result.PageResult;
import com.genntii.examManager.common.result.Result;
import com.genntii.examManager.domain.dto.ExamAddDTO;
import com.genntii.examManager.domain.question.mongo.QuestionBankMongo;
import com.genntii.examManager.domain.question.mongo.Vocabularies;
import com.genntii.examManager.domain.vo.QuestionBankMongoVO;
import com.genntii.examManager.service.ExamService;
import com.genntii.examManager.service.PracticeRecordService;
import com.genntii.examManager.service.PracticeService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/practice/t")
public class Practice4tController {

    @Resource
    private ExamService examService;

    @Resource
    private PracticeRecordService practiceRecordService;

    @Resource
    private PracticeService practiceService;

    @GetMapping("/questionBank")
    public Result<PageResult<QuestionBankMongoVO>> getQuestionBankList(@RequestParam("pageNum")Integer pageNum,
                                                                       @RequestParam("pageSize")Integer pageSize,
                                                                       @RequestParam("subjectId")Long subjectId,
                                                                       @RequestParam(value = "questionType", required = false) Byte questionType,
                                                                       @RequestParam(value = "keyword", required = false) String keyword){
        // questionType: 1-单选 2-多选 3-判断 4-简答
        return Result.success(examService.getQuestionBankList(pageNum, pageSize, subjectId,questionType,keyword));
    }

    @PostMapping
    public Result addExam(@RequestBody ExamAddDTO examAddDTO,
                          @RequestParam(required = false) ArrayList<Long> mongoId,
                          HttpServletRequest request){
        Long userId = Long.valueOf(String.valueOf(request.getAttribute(CommonConstant.TEACHER_ID))) ;
        practiceService.addExam(examAddDTO,mongoId,userId);
        return Result.success();
    }

    @PutMapping("/status")
    public void updateStatus(@RequestParam("status") Byte status,
                             @RequestParam("practiceId")Long practiceId){
        practiceService.setStatus(status,practiceId);
    }

    @GetMapping("/vocabulary/{examId}")
    public Result<PageResult<Vocabularies>> getVocabulary(@PathVariable("practiceId") Long practiceId,
                                                  @RequestParam("pageNum") Integer pageNum,
                                                  @RequestParam("pageSize") Integer pageSize){

//        return practiceRecordService.getVocabulary(pageNum, pageSize, practiceId);
        return null;
    }


}
